﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Threading;
using MongoDB.Bson.Serialization.Attributes;

namespace YmtAuth.Domain.Model.YmatouUser
{
    /// <summary>
    /// 用户标识
    /// </summary>
    public class UserIdIdentify : Entity<string>
    {
        private int _seed;
        [BsonElement("iSeed")]
        public int IdentifySeed { get; private set; }
        [BsonElement("mDate")]
        public DateTime ModifyDate { get; set; }

        public UserIdIdentify(int seed)
        {
            this.Id = "ymtuserid";
            this.IdentifySeed = seed;
        }

        public void Increment()
        {
            Interlocked.MemoryBarrier();
            this._seed = IdentifySeed;
            Interlocked.Increment(ref _seed);
            this.IdentifySeed = _seed;
        }

        protected override IEnumerable<object> CompareValues()
        {
            yield return this.IdentifySeed;
        }

        protected UserIdIdentify()
        {
        }
    }
}
